import java.util.*;
public class Day11 {
    public static void main(String[] args) {

    }
    public boolean wordBreak(String s, List<String> wordDict) {
        Set<String> set = new HashSet<>();
        for(int i=0;i< wordDict.size();i++) {
            set.add(wordDict.get(i));
        }
        int n = s.length();
        boolean[] dp = new boolean[n+1];
        dp[0]=true;
        s = " " + s;
        for(int i=1;i<n+1;i++) {
            for(int j=i;j>=1;j--) {
                if(dp[j-1] && set.contains(s.substring(j,i+1))) {
                    dp[i]=true;
                    break;
                }
            }
        }
        return dp[n];
    }
}
